#!/bin/bash

echo "========================================"
echo "   🌐 配置 HuggingFace 国内镜像"
echo "========================================"
echo ""

echo "【方案1】设置环境变量"
echo ""
echo "正在配置 HuggingFace 镜像..."

if [ -f ~/.zshrc ]; then
    SHELL_RC=~/.zshrc
    echo "检测到 zsh，配置文件: ~/.zshrc"
elif [ -f ~/.bashrc ]; then
    SHELL_RC=~/.bashrc
    echo "检测到 bash，配置文件: ~/.bashrc"
else
    SHELL_RC=~/.bash_profile
    echo "使用默认配置文件: ~/.bash_profile"
fi

echo "" >> $SHELL_RC
echo "# HuggingFace 国内镜像配置 (添加于 $(date +%Y-%m-%d))" >> $SHELL_RC
echo 'export HF_ENDPOINT=https://hf-mirror.com' >> $SHELL_RC

echo "✅ 已添加到 $SHELL_RC"
echo ""

export HF_ENDPOINT=https://hf-mirror.com

echo "✅ 当前会话已生效"
echo ""
echo "镜像地址: https://hf-mirror.com"
echo ""

echo "【验证配置】"
echo "HF_ENDPOINT = $HF_ENDPOINT"
echo ""

echo "========================================"
echo "   ✅ 配置完成！"
echo "========================================"
echo ""
echo "📝 说明："
echo "  1. 镜像已配置到 shell 配置文件"
echo "  2. 当前会话立即生效"
echo "  3. 下次打开终端自动生效"
echo ""
echo "🚀 现在可以运行："
echo "  ./运行音频翻译.sh"
echo ""
echo "💡 选择增强模式时，将使用国内镜像下载模型"
echo ""

